/**
 * @program: LeetCode
 * @description: LeetCode :剑指 Offer 56 - II. 数组中数字出现的次数 II
 * @author: WXY
 * @create: 2022-12-10 20:58
 * @Version 1.0
 **/


public class Num056_2_singleNumber {
    public static int singleNumber(int[] nums) {
        int[] arr = new int[32];
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < 32; j++) {
                arr[j] += nums[i] & 1;
                nums[i] = nums[i] >> 1;
            }
        }
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            ans += (1 << i) * (arr[i] % 3);
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] arr = {1, 1, 1, 2, 2, 2, 3};
        int number = singleNumber(arr);
        System.out.println(number);
    }
}
